<template lang="">
  <div class="register_container">
    <!-- 注册大标题 -->
    <div class="register_title">
      <h1>CUSTOM SIGNUP FORM</h1>
    </div>
    <!-- 外层容器 -->
    <el-container>
      <!-- 侧边栏容器 -->
      <el-aside width="350px">
        <div class="iconfont icon-regiser"></div>
        <div class="aside_text">
          <h2>Let's get you set up</h2>
          <h5>It should only take you a minute to register</h5>
        </div>
      </el-aside>
      <!-- 主要区域容器 -->
      <el-main>
        <!-- 注册表单区域 -->
        <el-form :model="registerForm" :rules="registerFormRules" ref="registerFormRef" label-width="100px">
          <!-- 用户名区域 -->
          <el-form-item label="Name" prop="name">
            <el-input v-model="registerForm.userName" size="small" clearable></el-input>
          </el-form-item>
          <!-- 性别区域 -->
          <el-form-item label="Gender">
            <div class="Gender_icon">
              <div @click="setSex(1)" :class="[registerForm.sex === 1? 'icon-change-nan': '', 'iconfont', 'icon-nan']"></div>
              <div @click="setSex(2)" :class="[registerForm.sex === 2? 'icon-change-nv': '', 'iconfont', 'icon-nv']"></div>
            </div>
          </el-form-item>
          <!-- 学号区域 -->
          <el-form-item label="Stunum" prop="stunum">
            <el-input v-model="registerForm.stuNumber" size="small" clearable></el-input>
          </el-form-item>
          <!-- 地址信息区域 -->
          <el-form-item label="Location">
              <el-select v-model="location" filterable placeholder="请选择">
                <el-option v-for="item in selectLocation" :key="item.id" :value="item.label">
                </el-option>
              </el-select>
          </el-form-item>
          <!-- 密码区域 -->
          <el-form-item label="Password" prop="password">
            <el-input v-model="registerForm.password" size="small" show-password></el-input>
          </el-form-item>
          <!-- 手机号码区域 -->
          <el-form-item label="Phone" prop="phone">
            <el-input v-model="registerForm.telephone" size="small" clearable></el-input>
          </el-form-item>
          <!-- register按钮 -->
          <el-form-item>
            <el-button type="success" @click="submitForm()">Sign Up</el-button>
          </el-form-item>
        </el-form>  
      </el-main>
    </el-container>
    <!-- 页脚文字容器 -->
    <div class="footer_container">
      <h4>© 2021 Custom Signup Form. All Rights Reserved | Design by MamBa_Zhen</h4>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      // 注册信息表单内容
      registerForm: {
        userName: '',
        sex: 0,
        stuNumber: '',
        password: '',
        telephone: '',
      },
      // 注册信息表单规则
      registerFormRules: {},
      // 注册信息区域学校
      selectLocation: [{
        id: '1',
        label: '黄金糕'
      }, {
        id: '2',
        label: '双皮奶'
      }],
      // 选中的注册信息location
      location: ''
    };
  },
  methods: {
    // 点击按钮，添加性别
    setSex(sex) {
      this.registerForm.sex = sex
    },
    // 点击按钮，提交数据表单
    submitForm() {
      this.$refs.registerFormRef.validate(async valid => {
        if (!valid) return
        const registerForm = {...this.registerForm, "location": this.location }
        const { data: res }  = await this.$http.post('user/ToRegister', registerForm)
        if (res.code !== 200) return this.$message.error(res.message)
        this.$message.success('注册成功')
        this.$router.push('/user/login')
      })
    }
  },
};
</script>
<style lang="less" scoped>
.register_container {
  overflow: hidden;
  background-color: rgb(49, 49, 49);
  background-size: cover;
  height: 100%;
  .register_title {
    text-align: center;
    color: white;
  }
  .el-container {
    width: 780px;
    height: 500px;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    .el-aside {
      background-color: #ccccff;
      display: flex;
      justify-content: center;
      align-items: center;
      flex-direction: column;
      .iconfont {
        color: #ffffff;
        font-size: 90px;
        margin-left: 25px;
      }
      .aside_text {
        text-align: center;
      }
    }
    .el-main {
      background-color: #99ccff;
      display: flex;
      align-items: center;
      justify-content: center;
      padding-top: 30px;
      .el-form {
        width: 100%;
        height: 100%;
        .el-form-item {
          .Gender_icon {
            display: flex;
            flex-wrap: nowrap;
            justify-content: space-around;
            .iconfont {
              font-size: 35px;
            }
            .icon-change-nv,.icon-nv:hover {
              color: rgb(232,1,81);
              cursor: pointer;
            }
            .icon-change-nan,.icon-nan:hover {
              color: rgb(0, 122, 216);
              cursor: pointer;
            }
          }
          button {
            width: 80%;
            position: absolute;
            left: 50%;
            transform: translate(-50%);
          }
        } 
      }
    }
  }
  .footer_container {
    text-align: center;
    position: absolute;
    bottom: 3%;
    left: 50%;
    transform: translateX(-50%);
    font-weight: 200;
    font-size: 1em;
    color: #cccccc;
  }
}
</style>
